﻿using System;
using System.Collections.Generic;
using CompactMapper.Orm.Annotations;
using CompactMapper.Orm.Extensions;

namespace CompactMapper.Orm.UnitOfWork.Mappings.Meta.PropertyInfos.Indexes
{
    internal class Index : PropertyInfoMeta
    {
        private readonly string _columnName;
        private readonly string _indexName;
        private readonly IEnumerable<String> _includeProperties;

        public IEnumerable<string> IncludeProperties
        {
            get { return _includeProperties; }
        }

        public String ColumnName { get { return _columnName; } }
        public string IndexName { get { return _indexName; } }


        public Index(PropertyInfoPersistenceAttributePair pair)
            : base(pair.PropertyInfo)
        {
            _columnName = pair.PropertyInfo.Name;
            _indexName = ((IndexAttribute)pair.PersistenceAttribute).IndexName;
            _includeProperties = ((IndexAttribute) pair.PersistenceAttribute).IncludeProperties.EmptyIfNull();
        }


        internal static Index From(PropertyInfoPersistenceAttributePair pair)
        {
            return new Index(pair);
        }
    }
}
